package ru.payment.wm.impl;

import org.dom4j.Element;
import ru.payment.wm.Invoice;
import ru.payment.wm.InvoiceState;

/**
 *
 * User: sergey
 * Date: 22.04.2009
 * Time: 14:28:57
 *
 */
public class InvoiceParser extends AbstractResponseParser<Invoice, Element> {

  public void parse(Element e, Invoice invoice) throws ProtocolException {
    if (e == null) {
      return;
    }

    invoice.setWmInvoiceId(e.attributeValue("id"));
    invoice.setWmTsId(e.attributeValue("ts"));

    invoice.setOrderId(asLong(e.element("orderid"), 0));
    invoice.setCustomerWmId(asString(e.element("customerwmid"), ""));
    invoice.setStorePurse(asString(e.element("storepurse"), ""));
    invoice.setAmount(asFloat(e.element("amount"), 0f));
    invoice.setDescription(asString(e.element("desc"), ""));
    invoice.setAddress(asString(e.element("address"), ""));

    invoice.setPeriod(asInt(e.element("period"), 0));
    invoice.setExpiration(asInt(e.element("expiration"), 0));
    int nState = asInt(e.element("state"), -1);
    invoice.setState(InvoiceState.getByValue(nState));
    invoice.setCreateDate(asDate(e.element("datecrt"), "yyyyMMdd HH:mm:ss"));
    invoice.setUpdateDate(asDate(e.element("dateupd"), "yyyyMMdd HH:mm:ss"));

    invoice.setCustomerPurse(asString(e.element("customerpurse"), ""));
    invoice.setWmTransactionId(asLong(e.element("wmtranid"), 0));

  }

}
